import formJs from "./regexDetail.js"; //新增弹框配置项
// import publicForm from "@/components/public/up-form.vue"; //弹框form  照片必填用
import publicForm from "@/components/public/el-form.vue"; //弹框form
import CustomDialog from "@/components/HntManage/pouringOrder/WBS/index.vue";
import tree from "@/components/TensionAndGrout/tree";
import TableData from "@/components/public/el-table-pagination"; //列表
import publicForm1 from "@/components/materialDataManage/fromCom.vue"; //弹框form

import {
    // 取样
    getWTDLetterByCompanyId, //预新增、详情
    getWtNumberByid, //改变委托单编号
    saveWTDLetter, //保存
    getBaseDataitemDetailByItemCode, //字典项
    // getfSampletype, //获取样品种类
    getPurveyorDataList, //厂家
    getUserCompanyTreeList, //查标段
    getWTDLetterHistoryList, //历史记录
    getEntryledgerPageLists,
    getSpeciesDataList,
    // 取样

    getfSampletypes, //样品种类


    updateWTDLetter
} from "@/api/request.js";
// 
export default {
    props: [
        "dialogVisible", //弹框是否展示
        "dialogTitle", //标题
        "statusNum", //按钮编号 1新增   2编辑取样   3编辑收样  7查看 8二次编辑
        "currentRow", //当前行
        "getList",
    ],
    data() {
        return {
            dialogEditVisible_cl: false, //新增弹框是否显示
            treelength: true, //左侧树显示隐藏
            navigatepageNums_cl: null, //是否显示分页
            queryCriteriaData_cl: {},
            table_config_cl: formJs.table_config_cl,
            rowInfo_cl: null,
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            treeData: [], //左侧树状图数据
            checkData: [],
            tableData_cl: [], //表格列表数据列表
            row_cl: {
                fId: "",
            }, //列表当前行信息
            getList_cl: {
                fCompanyid: "", //左侧选中组织机构id
                userId: "", //查询待办或已办时传 列表页查询不传
                modelType: 2, //0-待办 1-已办 传2 表示列表页查询
                keyType: "", //上方查询条件材料种类
                taskNumber: "", //上方查询条件进场编号
                startDates: "", //进场开始时间
                endDates: "", //进场结束时间
                page: 1, //当前页码
                pageSize: 15, //每页显示条数
            },
            searchObj: [{
                    select: true, //是input
                    label: ".", //字段
                    prop: "keyType", //字段名
                    width: 5, //参考el-col
                    disabled: false, //是否禁用
                    placeholder: "材料种类",
                    options: []

                },

            ],
            options1: [{
                    value: '==请选择==',
                    label: '==请选择=='
                },
                {
                    value: '硬化后水泥混凝土',
                    label: '硬化后水泥混凝土'
                }, {
                    value: '硬化后水泥砂浆',
                    label: '硬化后水泥砂浆'
                }, {
                    value: '硬化后水泥净浆',
                    label: '硬化后水泥净浆'
                },
            ],
            options2: [{
                    value: '==请选择==',
                    label: '==请选择=='
                },
                {
                    value: '钢筋试件',
                    label: '钢筋试件'
                },
            ],
            loading: false,
            visible: "", //弹框展示隐藏
            title: null, //弹框标题
            isLock: false, //取样按钮是否显示
            dialogHeight: null, //弹框高度
            // 取样
            companyTree: null, //机构树
            selected: [], //多选接值
            timeYMD: null, //当前日期
            timeYmdHms: null,
            btnShow: true,

            formObj: formJs.formObj3,
            // formObj1: formJs.formObj1, //详情--硬化
            // formObj2: formJs.formObj2, //详情--钢筋
            formObj3: formJs.formObj3, //详情--其他
            formData: {
                fId: "",
                fProjectid: "",
                fMaterialtype: "", //样品种类id
                fMaterialtypename: "", //样品种类名称
                fProjectname: "",
                fStatus: "", //待提交 已提交
                fCompanyid: "",
                fCompanyname: "",
                fWtunit: "", //委托单位
                fWtunitid: "", //委托单位id
                fWtunituser: "", //委托人
                fWtunituserid: "", //委托人ID
                fCheckunit: "", //受检单位
                fCheckunitid: "", //受检单位id
                fPhone: "", //联系电话
                fGcname: "", //工程名称
                fJzuser: "", //见证人
                fJzuserid: "", //见证人id
                fJzunit: "", //见证单位
                fJzunitid: "", //见证单位id 
                fJzphone: "", //见证人联系电话
                fChecktype: "", //检测类别
                fSamplelocation: "", //取样地点
                fBrand: "", //牌号
                fSampledates: "", //取样日期
                fSamplename: "", //样品名称
                fSampleid: "", //样品编码
                fSamplespecs: "", //规格
                fTesttype: "", //检测类型 检测类型为试件时 才能有牌号
                fStrengthgrade: "", //强度
                fManufacturer: "", //厂家
                fPlace: "", //产地
                fProjectlocation: "", //工程部位
                fProjectlocationid: "", //工程部位id
                fProductiondates: "", //样品生产日期
                fSampleno: "", //样品批号
                fSamplenum: "", //样品数量
                fDeputynum: "", //代表数量
                fSamplemessage: "", //样品描述
                fJcparameters: "", //检测参数
                fJcbasis: "", //检测依据
                fPdbasis: "", //判定依据
                fFjnotes: "", //附加说明
                fCommissiondates: "", //委托日期
                fSamplecollector: "", //收样人
                fSamplecollectorid: "", //收样人id
                fTestingfees: "", //检测费用
                fSampledisposal: "", //样品处置
                fWtnumber: "", //委托单编号
                fEntrynumber: "",
                fEntryledgerid: ""
            },

            fSampletypeList: [], //样品种类总集合

            WBSShow: false, // WBS
            // 取样
            userInfo: {}, //登录用户
            currentDetail: null,
            fCompanynames: null,
            fCompanyids: null,
        };
    },
    components: {
        publicForm,
        publicForm1,
        tree,
        TableData,
        CustomDialog,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                }
            },
            immediate: true,
        },
        getList: {
            handler(newVal) {
                if (newVal) {
                    // this.getList = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));

        this.btnShow = true;
        // this.formObj1.map(item => {
        //     item.disabled = false;
        // });
        // this.formObj2.map(item => {
        //     item.disabled = false;
        // });
        this.formObj3.map(item => {
            item.disabled = false;
        });
        // this.formObj1[0].disabled = true;
        // this.formObj2[0].disabled = true;fCheckunit
        this.formObj3[0].disabled = true;

        // this.formObj1[1].disabled = true;
        // this.formObj2[1].disabled = true;
        this.formObj3[1].disabled = true;

        // this.formObj1[2].disabled = true;
        // this.formObj2[2].disabled = true;
        this.formObj3[18].inputButton = true;
        this.getSpeciesList()
        if (this.statusNum == 1) { //新增
            this.addition(); //取样
            this.getTree(); //标段

        } else if (this.statusNum == 2) { //2编辑
            this.getDetail({
                fId: this.currentDetail.fId
            }) //取样
            this.getTree(); //标段
        }else if (this.statusNum == 8) { //2编辑
            this.getDetail({
                fId: this.currentDetail.fId
            }) //取样
            this.getTree(); //标段
        }  else if (this.statusNum == 7) { //查看
            this.btnShow = false //按钮
            // this.formObj1.map(item => {
            //     item.disabled = true;
            // });
            // this.formObj2.map(item => {
            //     item.disabled = true;
            // });
            this.formObj3[18].inputButton = false;
            this.formObj3.map(item => {
                item.disabled = true;
            });
            this.getDetail({
                fId: this.currentDetail.fId
            }) // currentRow
        }
        this.getHeight();
        this.getData();
    },
    methods: {
        getSpeciesList() {
            var obj = {
                page: 1,
                pageSize: 500
            }
            getSpeciesDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {

                        this.searchObj[0].options = [{
                            label: "请选择材料种类",
                            value: "",
                        }]
                        res.data.pageInfo.list.map(item => {
                            if (item.fStatus == 1) {
                                this.searchObj[0].options.push({
                                    label: item.fVarietyname,
                                    value: item.fVarietyname,
                                    children: item.materialList
                                })
                            }
                        })

                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 材料进场编号
        inputFocus(index, prop) {
            // console.log("inputFocus", index, prop);
            if (prop == "fEntrynumber") {
                // this.getTree1("fEntrynumber");
                if (this.formData.fCheckunitid != '' && this.formData.fCheckunitid != null) {
                    this.getList_cl.fCompanyid = this.formData.fCheckunitid;
                    this.yj_searchForm_cl(this.getList_cl)
                } else {
                    this.$message.warning("请先选择受检单位");
                }
               
            }

            return index, prop;
        },


        // 列表
        yj_searchForm_cl(data) {
            this.loadingEditDialog_cl = true;
            getEntryledgerPageLists(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loadingEditDialog_cl = false;
                        this.dialogEditVisible_cl = true;
                        this.tableData_cl = res.data.pageInfo.list;
                        this.queryCriteriaData_cl = res.data.pageInfo;
                        this.navigatepageNums_cl =
                            res.data.pageInfo.navigatepageNums;
                    } else {
                        this.$message.error(res.msg);
                        this.loadingEditDialog_cl = false;
                    }
                })

        },
        // 点击当前
        rowChange_cl(val) {
            console.log(33);

            this.rowInfo_cl = val;

        },
        // 点击查看
        yj_viewForm_cl(row, label) {
            console.log(55);
            this.rowInfo_cl = row;


            return label;
        },
        // 保存
        yj_saveForm_cl() {
            // console.log(this.rowInfo_cl, this.rowInfo_cl != null);
            // if (this.rowInfo_cl.fEntrynumber != this.formData.fEntrynumber) {
            //     this.formData.fSampletype = ""; //样品种类id 隐藏
            //     this.formData.fSampletypename = ""; //样品种类汉字
            //     this.formData.fSamplemodel = ""; //样品编码
            // }
            if (this.rowInfo_cl != null) {

                this.formData.fEntryledgerid = this.rowInfo_cl.fId; //材料进场编号id 隐藏
                this.formData.fEntrynumber = this.rowInfo_cl.fEntrynumber; //材料进场编号
                this.formData.fMaterialtypeid = this.rowInfo_cl.fMaterialtypeid; //材料进场材料种类id
                // this.formData.fSamplespecs = this.rowInfo_cl.fSpecification; //规格型号
                // this.formData.fBusinessscopename = this.rowInfo_cl.fCompanyname; //取样标段
                // this.formData.fSampleno = this.rowInfo_cl.fBatchnumber; //批号/编号
                // this.formData.fManufacturer = this.rowInfo_cl.fManufacturername; //生产厂家
                // this.formData.fApproachdates = this.rowInfo_cl.fEntrydates; //进场日期
                this.getfSampletypeFuns(this.rowInfo_cl)
                this.$forceUpdate()
            }
            console.log(this.formData);
            this.dialogEditVisible_cl = false;

            // 




        },

        // 材料进场编号
        getWTDLetterHistoryList(data) {

            getWTDLetterHistoryList(data).then(res => {

                if (res.errcode == 0) {
                    var fJzunitNum; //见证单位
                    var fGcnameNum; //工程名称
                    var fSamplespecsNum; //规格型号
                    this.formObj.map((item, index) => {
                        if (item.prop == 'fJzunit') {
                            fJzunitNum = index //见证单位Index
                        } else if (item.prop == 'fGcname') {
                            fGcnameNum = index //工程名称Index
                        } else if (item.prop == 'fSamplespecs') {
                            fSamplespecsNum = index //规格型号Index
                        }
                    })

                    this.formObj[fSamplespecsNum].options = [] //规格型号
                    res.data.fSamplespecslist.map(item => {
                        this.formObj[fSamplespecsNum].options.push({ //规格型号
                            label: item.keyvalue,
                            value: item.keyvalue,
                        })
                    })


                    this.formObj[fJzunitNum].options = [] //见证单位
                    this.formObj[fGcnameNum].options = [] //工程名称

                    res.data.fJzunitlist.map(item => {
                        this.formObj[fJzunitNum].options.push({ //见证单位
                            label: item.keyvalue,
                            value: item.keyvalue,
                        })
                    })
                    res.data.fGcnamelist.map(item => {
                        this.formObj[fGcnameNum].options.push({ //工程名称
                            label: item.keyvalue,
                            value: item.keyvalue,
                        })
                    })
                }
            })
        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        selectChange(value, index, prop) {
            console.log("selectChange", value, index, prop);
            if (prop == 'fGcname') { //工程名称
                this.formData.fGcname = value.label || value
            }
            if (prop == 'fJzunit') { //见证单位
                this.formData.fJzunit = value.label || value
            }
            if (prop == 'fSamplespecs') { //规格型号
                this.formData.fSamplespecs = value.label || value
            }
            if (prop == "fManufacturer") {
                this.formData.fManufacturer = value.label || value

            }
            // 取样标段
            if (prop == "fCheckunit") {
                this.getfSampletypeFuns({fMaterialtypeid:""})

                this.companyTree.map(item => {
                    if (value == item.fShortname) {
                        this.formData.fCheckunit = item.fShortname;
                        this.formData.fCheckunitid = item.fCompanyid;
                        this.formData.fCompanyname = item.fShortname;
                        this.formData.fCompanyid = item.fCompanyid;
                        this.getWTDLetterHistoryList({
                            fCompanyid: item.fCompanyid
                        })
                        this.getWtNumber();
                    }
                })
            }
            //取样日期
            if (prop == "fSampledates") {
                if (this.formData.fCheckunitid != null && this.formData.fCheckunitid != "") {
                    this.getWtNumber();
                } else {
                    this.formData.fSampledates = this.timeYMD;
                    this.$message.error("请先选择受检单位");
                }
            }
        },

        clickDialog(index, prop) {
            // console.log("clickDialog", index, prop);
            if (prop == "fProjectlocation") {
                // 调WBS
                this.WBSShow = true;
            }
            return index, prop;
        },

        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 取样新增
        addition() {
            this.loading = true;
            this.formObj = this.formObj3;

            this.formObj[15].options = [];
            this.formObj[6].options = [];
            this.formObj[8].options = [];

            var src = {
                fCompanyid: this.userInfo.companyId, //当前登录人项目id
                fId: "",
            };
            getWTDLetterByCompanyId(src)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        var data = res.data.yjQmpYpLetterAuthorization;
                        that.formData.fWtunit = data.fWtunit;
                        that.formData.fWtunitid = data.fWtunitid;
                       
                        that.getPurveyorData(); //生产厂家
                        that.formData.fWtunit = data.fWtunit;
                        that.formData.fWtunitid = data.fWtunitid;

                        this.formData.fPhone = this.userInfo.mobile;
                        this.formData.fEntrynumber = "";
                        this.formData.fEntryledgerid = "";

                        if (that.formData.fWtunituser == null || that.formData.fWtunituser == "") {
                            that.formData.fWtunituser = that.userInfo.realName; //委托人
                            that.formData.fWtunituserid = that.userInfo.userId; //委托人ID
                        }
                        if (that.formData.fSampledates == null || that.formData.fSampledates == "") {
                            that.formData.fSampledates = that.timeYMD; //取样日期
                        }
                        if (that.formData.fCommissiondates == null || that.formData.fCommissiondates == "") {
                            that.formData.fCommissiondates = that.timeYMD; //委托日期
                        }
                        console.log(this.formData);
                    } else {
                        this.loading = false;
                        this.$message.error(res.errcode, res.msg);
                    }
                })
                .catch(() => {
                    console.log("预新增接口报错");
                });
        },
        // 详情
        getDetail(obj) {
            this.loading = true;
            this.formObj = this.formObj3;
            getWTDLetterByCompanyId(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.formData = res.data.yjQmpYpLetterAuthorization;
                        // if (that.formData.fSampletypename == '硬化后水泥混凝土' || that.formData.fSampletypename == '硬化后水泥砂浆' || that.formData.fSampletypename == '硬化后水泥净浆') {
                        //     this.formObj = this.formObj1;
                        // } else if (that.formData.fSampletypename == '钢筋原材' || that.formData.fSampletypename == '钢筋焊接' || that.formData.fSampletypename == '钢筋机械连接') {
                        //     this.formObj = this.formObj2;
                        // } else {
                        //     this.formObj = this.formObj3;
                        // }
                        // if (that.primaryInfo.status == 2) { // 编辑
          
                            that.getfSampletypeFuns(that.formData); //样品种类
                            that.getPurveyorData(); //生产厂家
                            // if (that.formData.fSampletypename == "硬化后水泥混凝土") {
                            //     this.getStrengthgrade("StrengthGrade1");
                            //     // this.getSpecimenage("SpecimenAge1");
                            //     this.getSpecimensize("SpecimenSize1");
                            // } else if (that.formData.fSampletypename == "硬化后水泥砂浆") {
                            //     this.getStrengthgrade("StrengthGrade3");
                            //     // this.getSpecimenage("SpecimenAge3");
                            //     this.getSpecimensize("SpecimenSize3");
                            // } else if (that.formData.fSampletypename == "硬化后水泥净浆") {
                            //     this.getStrengthgrade("StrengthGrade4");
                            //     // this.getSpecimenage("SpecimenAge4");
                            //     this.getSpecimensize("SpecimenSize4");
                            // } else if (that.formData.fSampletypename == '钢筋原材' || that.formData.fSampletypename == '钢筋焊接' || that.formData.fSampletypename == '钢筋机械连接') {
                            //     this.getBrand("Brand");
                            //     this.getDiameter("Diameter");
                            // }

                            if (that.formData.fWtunituser == null || that.formData.fWtunituser == "") {
                                that.formData.fWtunituser = that.userInfo.userName; //委托人
                                that.formData.fWtunituserid = that.userInfo.id; //委托人ID
                            }
                            if (that.formData.fSampledates == null || that.formData.fSampledates == "") {
                                that.formData.fSampledates = that.timeYMD; //取样日期
                            }
                            if (that.formData.fCommissiondates == null || that.formData.fCommissiondates == "") {
                                that.formData.fCommissiondates = that.timeYMD; //委托日期
                            }
                        // }
                    } else {
                        this.loading = false;
                        this.$message.error(res.msg);
                    }
                })
                // .catch(() => {
                //     this.loading = false;
                //     console.log("取样详情接口报错");
                // });
        },
        // 改委托单编号
        getWtNumber() {
            var obj = {
                fCompanyid: this.formData.fCheckunitid,
                startDates: this.formData.fSampledates
            }
            getWtNumberByid(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.formData.fWtnumber = res.data.fWtnumber;
                    } else {
                        this.loading = false;
                        this.$message.error(res.msg);
                    }
                })
                .catch(() => {
                    console.log("改委托单编号接口报错");
                });
        },

        yj_saveForm() {
            if (this.$refs.publicForm.submitForm()) {
                this.saveForm(this.formData);
            } else {
                console.log("error");
            }
        },

        // 保存
        saveForm(data) {
            this.loading = true;
            this.isLock = true
            data.userId = this.userInfo.userId;
            data.userName = this.userInfo.realName;
            var str;
            if(this.statusNum==8){
                str=updateWTDLetter;
            }else {
                str=saveWTDLetter;
            }
            str(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.$emit("refreshList");
                        this.isLock = false
                        this.visible = false;
                        this.$message.success("保存成功");
                    } else {
                        this.loading = false;

                        this.isLock = false
                        this.$message.error(res.msg);
                    }
                })
                .catch(() => {
                    console.log("保存接口报错");
                });
        },
        // 查标段
        getTree() {
            var treeText = {
                companyId: this.userInfo.companyId,
                userId: this.userInfo.userId,
            };
            getUserCompanyTreeList(treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.companyTree = res.data.userCompanyTreeList;
                        // this.formObj1[3].options = [];
                        // this.formObj2[3].options = [];
                        this.formObj3[3].options = [];
                        this.companyTree.map(item => {
                            if (item.fCompanyid != this.userInfo.companyId) {
                                // this.formObj1[3].options.push({
                                //     value: item.fShortname,
                                //     label: item.fShortname
                                // });
                                // this.formObj2[3].options.push({
                                //     value: item.fShortname,
                                //     label: item.fShortname
                                // });
                                this.formObj3[3].options.push({
                                    value: item.fShortname,
                                    label: item.fShortname
                                });
                            }
                        })
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },

        // 时间
        getData() {
            var time = new Date();
            const y = time.getFullYear();
            const m = (time.getMonth() + 1 + "").padStart(2, "0");
            const d = (time.getDate() + "").padStart(2, "0");
            const hh = (time.getHours() + "").padStart(2, "0");
            const mm = (time.getMinutes() + "").padStart(2, "0");
            const ss = (time.getSeconds() + "").padStart(2, "0");
            this.timeYMD = `${y}-${m}-${d}`;
            this.timeYmdHms = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
        },

        // WBS
        refreshList() {},
        WBSDialog() { // WBS树关闭
            this.WBSShow = false;
        },
        getWBS(data) { //获取选择WBS信息
            this.formData.fProjectlocation = data.fLongname //工程部位
            this.formData.fProjectlocationid = data.fNodeid //工程部位id
        },
        // WBS
        getfSampletypeFuns(data) {
            // fMaterialtypeid

            getfSampletypes({
                    fMaterialtypeid: data.fMaterialtypeid
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.fSampletypeList = this.tranListToTreeData(
                            res.data.SampletypeList
                        );

                        // this.formObj1[13].tree.treeData = this.fSampletypeList;
                        // this.formObj1[13].tree.checkData = [
                        //     this.fSampletypeList[0].fSampletype,
                        // ];

                        // this.formObj2[13].tree.treeData = this.fSampletypeList;
                        // this.formObj2[13].tree.checkData = [
                        //     this.fSampletypeList[0].fSampletype,
                        // ];

                        this.formObj3[13].tree.treeData = this.fSampletypeList;
                        this.formObj3[13].tree.checkData = [
                            this.fSampletypeList[0].fSampletype,
                        ];
                    } else {
                        this.$message.error("获取样品种类", res.msg);
                    }
                })
                .catch((error) => {
                    console.log("获取样品种类 接口出错", error.msg);
                });
        },

        tranListToTreeData(data) {
            let result = [];
            if (!Array.isArray(data)) {
                return result;
            }
            // 清除已存在的数据  重新赋值
            data.forEach((item) => {
                delete item.children;
            });

            let map = {};
            data.forEach((item) => {
                map[item.fSampletype] = item;
            });

            data.forEach((item) => {
                let parent = map[item.fParentId];
                if (parent) {
                    (parent.children || (parent.children = [])).push(item);
                } else {
                    result.push(item);
                }
            });
            return result;
        },

        // // 获取样品种类
        // getfSampletypeFun() {
        //     var data = {
        //         fChecktypenum: 1, //0自检1外委
        //         fMaterialtypeid: "", //材料进场材料种类id
        //     };
        //     getfSampletype(data)
        //         .then((res) => {
        //             if (res.errcode == 0) {
        //                 this.fSampletypeList = this.tranListToTreeData(
        //                     res.data.SampletypeList
        //                 );
        //                 this.formObj1[12].tree.treeData = this.fSampletypeList;
        //                 this.formObj1[12].tree.checkData = [
        //                     this.fSampletypeList[0].fSampletype,
        //                 ];

        //                 this.formObj2[12].tree.treeData = this.fSampletypeList;
        //                 this.formObj2[12].tree.checkData = [
        //                     this.fSampletypeList[0].fSampletype,
        //                 ];

        //                 this.formObj3[12].tree.treeData = this.fSampletypeList;
        //                 this.formObj3[12].tree.checkData = [
        //                     this.fSampletypeList[0].fSampletype,
        //                 ];
        //             } else {
        //                 this.$message.error("获取样品种类", res.msg);
        //             }
        //         })
        //         .catch((error) => {
        //             console.log("获取样品种类 接口出错", error.msg);
        //         });
        // },

        // tranListToTreeData(data) {
        //     let result = [];
        //     if (!Array.isArray(data)) {
        //         return result;
        //     }
        //     // 清除已存在的数据  重新赋值
        //     data.forEach((item) => {
        //         delete item.children;
        //     });

        //     let map = {};
        //     data.forEach((item) => {
        //         map[item.fSampletype] = item;
        //     });

        //     data.forEach((item) => {
        //         let parent = map[item.fParentId];
        //         if (parent) {
        //             (parent.children || (parent.children = [])).push(item);
        //         } else {
        //             result.push(item);
        //         }
        //     });
        //     return result;
        // },
        handleNode(data) {
            // console.log("handleNode", data);
            this.formData.fMaterialtypename = data.fSampletypename; //样品种类名称
            this.formData.fMaterialtype = data.fSampletype; //样品种类id

            // if (data.fSampletypename == '硬化后水泥混凝土' || data.fSampletypename == '硬化后水泥砂浆' || data.fSampletypename == '硬化后水泥净浆') {
            //     this.formObj = this.formObj1;
            //     if (data.fSampletypename == "硬化后水泥混凝土") {
            //         this.getStrengthgrade("StrengthGrade1");
            //         // this.getSpecimenage("SpecimenAge1");
            //         this.getSpecimensize("SpecimenSize1");
            //     }
            //     if (data.fSampletypename == "硬化后水泥砂浆") {
            //         this.getStrengthgrade("StrengthGrade3");
            //         // this.getSpecimenage("SpecimenAge3");
            //         this.getSpecimensize("SpecimenSize3");
            //     }
            //     if (data.fSampletypename == "硬化后水泥净浆") {
            //         this.getStrengthgrade("StrengthGrade4");
            //         // this.getSpecimenage("SpecimenAge4");
            //         this.getSpecimensize("SpecimenSize4");
            //     }
            // } else if (data.fSampletypename == '钢筋原材' || data.fSampletypename == '钢筋焊接' || data.fSampletypename == '钢筋机械连接') {
            //     this.formObj = this.formObj2;
            //     this.getBrand("Brand");
            //     this.getDiameter("Diameter");

            // } else {
            //     this.formObj = this.formObj3;
            // }
            // this.formData.fMaterialtype = data.fSampletype; //样品种类id 隐藏
            // this.formData.fMaterialtypename = data.fSampletypename; //样品种类汉字
            // this.formData.fSamplename = ""; //样品名称
            // this.formData.fSamplespecs = ""; //规格
            // this.formData.fStrengthgrade = ""; //强度
            // this.formData.fBrand = ""; //牌号
        },
        // 获取样品种类

        //生产厂家List
        getPurveyorData() {
            var data = {
                page: 1,
                pageSize: 500,
                merchantName: "", //生产厂家
                fVarietyid: "", //种类ID
                typ: "1", //"1"材料生产商，"2"材料供应商
            };
            getPurveyorDataList(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        // this.formObj1[16].options = [];
                        // this.formObj2[16].options = [];
                        this.formObj3[16].options = [];
                        res.data.pageInfo.list.map((item) => {
                            // this.formObj1[16].options.push({
                            //     value: item.fMerchantname,
                            //     label: item.fMerchantname,
                            // });
                            // this.formObj2[16].options.push({
                            //     value: item.fMerchantname,
                            //     label: item.fMerchantname,
                            // });
                            this.formObj3[16].options.push({
                                value: item.fMerchantname,
                                label: item.fMerchantname,
                            });
                        });
                    } else {
                        this.$message.error("生产厂家获取失败", res.msg);
                    }
                })
                .catch((error) => {
                    console.log("获取生产厂家 接口出错", error.msg);
                });
        },
        //生产厂家List

        // 字典项
        // 强度等级
        getStrengthgrade(data) {
            getBaseDataitemDetailByItemCode({
                    fItemcode: data
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.formObj1[16].options = [];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.formObj1[16].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                    } else {
                        this.$message.error("强度等级", res.msg);
                    }
                })
                .catch(() => {
                    console.log("字典--强度等级接口报错");
                });
        },
        // //试件龄期
        // getSpecimenage(data) {
        //     getBaseDataitemDetailByItemCode({
        //         fItemcode: data
        //     })
        //         .then((res) => {
        //             if (res.errcode == 0) {
        //                 this.formObjText1[11].options = [];
        //                 res.data.baseDataitemdetailList.map((item) => {
        //                     this.formObjText1[11].options.push({
        //                         value: item.fItemname,
        //                         label: item.fItemvalue,
        //                     });
        //                 });
        //             } else {
        //                 this.$message.error("试件龄期", res.msg);
        //             }
        //         })
        //         .catch(() => {
        //             console.log("字典--试件龄期接口报错");
        //         });
        // },
        //试件尺寸
        getSpecimensize(data) {
            getBaseDataitemDetailByItemCode({
                    fItemcode: data
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.formObj1[15].options = [];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.formObj1[15].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                    } else {
                        this.$message.error("试件尺寸", res.msg);
                    }
                })
                .catch(() => {
                    console.log("字典--试件尺寸接口报错");
                });
        },
        //牌号
        getBrand(data) {
            getBaseDataitemDetailByItemCode({
                    fItemcode: data
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.formObj2[16].options = [];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.formObj2[16].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                    } else {
                        this.$message.error("牌号", res.msg);
                    }
                })
                .catch(() => {
                    console.log("字典--牌号接口报错");
                });
        },
        //直径
        getDiameter(data) {
            getBaseDataitemDetailByItemCode({
                    fItemcode: data
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.formObj2[15].options = [];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.formObj2[15].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                    } else {
                        this.$message.error("直径", res.msg);
                    }
                })
                .catch(() => {
                    console.log("字典--直径接口报错");
                });
        },
        // 字典项
    },
};